/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.service;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.expert.dao.ProductCategoryDao;
import com.chlitina.store.modules.expert.entity.ProductCategory;
import com.chlitina.store.modules.sys.utils.StoreUtils;

/**
 * 产品分类Service
 * @author lvbo
 * @version 2013-06-03
 */
@Component
@Transactional(readOnly = true)
public class ProductCategoryService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(ProductCategoryService.class);
	
	@Autowired
	private ProductCategoryDao productCategoryDao;
	
	public ProductCategory get(Long id) {
		return  productCategoryDao.findOne(id);
	}
	
	public Page<ProductCategory> find(Page<ProductCategory> page, String searchName) {
		if (!StringUtils.isNotEmpty(searchName)){
			searchName = "";
		}
		Long storeTypeId = StoreUtils.getStore().getStoreType().getId();
		String sql = "select pc.* from product_category pc JOIN product_category_store_type pcst ON pc.NAME like '%"+ 
				searchName +"%' AND pcst.STORE_TYPE_ID = " + storeTypeId + " AND pc.ID = pcst.PRODUCT_CATEGORY_ID";
		return productCategoryDao.findBySql(page, sql);
	}
}
